<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<c:if test="${sessionScope.admin==null }" >
<meta http-equiv="refresh" content="0;url=admin_login.jsp">
</c:if> 

<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>抢答</title>
<script type="text/javascript" src="Dialog.js"></script>
<script type="text/javascript">
var xmlHttp = false;
function doIt(){
    sendRequest("GET","start_qinagda.action",true,callback);
}

function view_latest_result(){
	
    sendRequest("GET","view_latest_result.action",true,callback1);
}

function sendRequest(method, url, async, callback) {
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        //xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        var msxmls = ["MSXML3" , "MSXML2" , "Microsoft"];
        for(var i=0; i < msxmls.length; i++)
        {
        	try
        	{
        		xmlHttp = new ActiveXObject(msxmls[i]+".XMLHTTP");
        	}
        	catch(e)
        	{
        		//alert("您的浏览器不支持XMLHTTP控件");
        	}
        }
    }
    if (!xmlHttp) {
    	Dialog.alert("当前浏览器无法创建XMLHttpRequest对象");
    } else {
        //初始化XMLHttpRequest对象
        xmlHttp.open(method, url, async);
        //定义一个回调函数
        xmlHttp.onreadystatechange = callback;
        //发送
        xmlHttp.send();
    }
}
function callback(){
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var str = xmlHttp.responseText;
        //alert(str);
        var obj = eval("(" + str + ")");
        Dialog.alert(obj.name + " : " + obj.age);
    }
}

function callback1(){
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var str = xmlHttp.responseText;
        //alert(str);
        var obj = eval("(" + str + ")");
       //alert(obj[0].qiangda_id);
      // alert(obj.length);
      var result ="";
      
      for(var i=1;i<=obj.length;i++){
    	  result = result + "<br/>" + "第" + i + "名:" + obj[i-1].ip ;//+ "  "+ obj[i-1].qiangda_time;
    	// alert(obj[i].ip);
      }
      //alert(result);
      document.getElementById("text").innerHTML = result;
     //document.getElementById("result")innerHTML = result;
    }
}
</script>
</head>
<body align="center">
<input type="image" src="images/kaishiqiangda.jpg" onclick="doIt()" />
<br/>
<a href="#" onclick="view_latest_result();return false;">查看最新一轮抢答结果</a>
<br/>
<span id="text"></span>
</body>
</html>